{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "HHgvBhnB5_uo"
   },
   "source": [
    "\n",
    "## Question-1\n",
    "\n",
    "Write a program that inputs an integer value (stop_number) from the user and prints the sum of all numbers from 0 to stop_number. You can assume the user will enter a valid value."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "N32FAirH5-J2"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Please enter a stop number: 9\n",
      "0\n",
      "1\n",
      "3\n",
      "6\n",
      "10\n",
      "15\n",
      "21\n",
      "28\n",
      "36\n",
      "36\n"
     ]
    }
   ],
   "source": [
    "stop_number = int(input(\"Please enter a stop number: \"))\n",
    "\n",
    "result = 0\n",
    "for i in range(0, stop_number):\n",
    "    result = result + i\n",
    "    print(result)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "G63Y7XEL6KmJ"
   },
   "source": [
    "## Question-2\n",
    "\n",
    "Extend your program to also input the start_number from the user. In this case, your program will add all numbers from start_number to stop_number. You can assume that the user will enter two valid values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "10xHuwEH6LeW"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Please enter a start number: 3\n",
      "Please enter a stop number: 9\n",
      "33\n"
     ]
    }
   ],
   "source": [
    "start_number = int(input(\"Please enter a start number: \"))\n",
    "stop_number = int(input(\"Please enter a stop number: \"))\n",
    "\n",
    "result = 0\n",
    "for i in range(start_number, stop_number):\n",
    "  result += i\n",
    "  \n",
    "print(result) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "_Bu5hGFw6QOK"
   },
   "source": [
    "## Question-3\n",
    "\n",
    "Extend your program to check if the start_number is an integer between 0 and 100. If so, your program will continue to ask for the second input and perform calculations; otherwise, it prints an error and stops execution."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "VofmbOeA6Tlg"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Please enter a start number: 23\n",
      "Please enter a stop number: 55\n",
      "1232\n"
     ]
    }
   ],
   "source": [
    "start_number = int(input(\"Please enter a start number: \"))\n",
    "\n",
    "if 0 <= start_number <= 100:\n",
    "  stop_number = int(input(\"Please enter a stop number: \"))\n",
    "  \n",
    "  if start_number <= stop_number <= 100:\n",
    "  \n",
    "    result = 0\n",
    "    for i in range(start_number, stop_number):\n",
    "      result += i\n",
    "    print(result)\n",
    "  else:\n",
    "    print(\"Invalid stop number\")\n",
    "\n",
    "  \n",
    "else:\n",
    "  print(\"Invalid start number\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "9NqX9G3F8uZQ"
   },
   "source": [
    "### Modules\n",
    "\n",
    "They are tools that contain some functions and attributes that enable us to perform some functions easily. It provides the opportunity to use these functions it hosts in different files and programs over and over again. Thanks to the modules, Python has become a much more useful and easy-to-implement.\n",
    "\n",
    "In order to use any module in Python, we first need to 'import' it. Importing means making functions and attributes within one module available from within another program.\n",
    "\n",
    "**import <module_name>**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "MDmE3VeY2BUv"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Please enter you guess: 5\n",
      "Please enter a greater number!!\n",
      "Please enter you guess: 30\n",
      "Please enter a smaller number!!\n",
      "Please enter you guess: 23\n",
      "Please enter a smaller number!!\n",
      "Please enter you guess: 12\n",
      "Please enter a smaller number!!\n",
      "Please enter you guess: 7\n",
      "Please enter a greater number!!\n",
      "Looseer..The number was:  9\n"
     ]
    }
   ],
   "source": [
    "import random as rnd\n",
    "\n",
    "secret = rnd.randint(1,100)\n",
    "\n",
    "check = False\n",
    "\n",
    "#guess = int(input(\"Please enter you guess: \"))\n",
    "\n",
    "for x in range(5):\n",
    "  guess = int(input(\"Please enter you guess: \"))\n",
    "  if guess == secret:\n",
    "    print(\"Congrats!!\")\n",
    "    check = True\n",
    "    break\n",
    "  elif guess < secret:\n",
    "    print(\"Please enter a greater number!!\")\n",
    "  else: \n",
    "    print(\"Please enter a smaller number!!\")\n",
    "    \n",
    "if not check:\n",
    "  print(\"Looseer..The number was: \", secret)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "IdVXxCBHJ07g"
   },
   "source": [
    "# Dictionaries\n",
    "\n",
    "\n",
    "\n",
    "* A data type in Python.\n",
    "* Dictionaries are indexed by keys and these keys can be a String and integer type.\n",
    "* Shown as key:value pairs and keys are the unique values.\n",
    "*   {}\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = {}\n",
    "\n",
    "print(d)\n",
    "type(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "n5qcMd-GLsKa",
    "outputId": "b93ee552-50e7-49ba-cc11-8d09887643f1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'python': 1, 'course': 2}\n"
     ]
    }
   ],
   "source": [
    "d = {\"python\":1, \"course\":2}\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "EX9oMWnHL7fq",
    "outputId": "011a543e-a1fa-4d88-d8e8-822e4a806955"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning', 'artificial': 'intelligence'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2 = {\"machine\":\"learning\", \"artificial\":\"intelligence\" }\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 36
    },
    "colab_type": "code",
    "id": "eckt9hWHMKyB",
    "outputId": "2574c92e-966b-4f7a-faf9-b6b782bda0b4"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'intelligence'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2[\"artificial\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning', 'artificial': 'intelligence', 'java': 'programming'}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2[\"java\"] = \"programming\"\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'programming'}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2[\"ruby\"] = \"programming\"\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language'}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2[\"ruby\"] = \"language\"\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'python': 1, 'course': 2}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "EtB2gyEmMWjy",
    "outputId": "f16e2223-550d-401d-b669-228d34ce8982"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d[\"course\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "t2flZAV2NIIq",
    "outputId": "9ee61c7c-b81b-4965-d128-fdb44d16e691"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language',\n",
       " 'deep': 'learning'}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2[\"deep\"] = \"learning\"\n",
    "d2\n",
    "#print(d2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'python': 1, 'course': 2}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "ntLDke2enyh6",
    "outputId": "e64c7450-f5cb-4ef4-ac96-c32e702e799d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['python', 'course'])\n"
     ]
    }
   ],
   "source": [
    "print(d.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['machine', 'artificial', 'java', 'ruby', 'deep'])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "RRCll5K-oEW6",
    "outputId": "ca0a5e9d-4b4c-4f91-fc2e-6581f76dc6f2"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values(['learning', 'intelligence', 'programming', 'language', 'learning'])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "YYzF_DyGoHWm",
    "outputId": "efa04009-abdf-40e1-d177-cb046ff201b7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_items([('machine', 'learning'), ('artificial', 'intelligence'), ('java', 'programming'), ('ruby', 'language'), ('deep', 'learning')])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "rcKOifmfoap9",
    "outputId": "fdea2f68-ed1b-45c2-ba42-54e7e56b2ae4"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "machine\n",
      "artificial\n",
      "java\n",
      "ruby\n",
      "deep\n"
     ]
    }
   ],
   "source": [
    "for k in d2.keys():\n",
    "  print(k)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 52
    },
    "colab_type": "code",
    "id": "bhSGEUT5oqc3",
    "outputId": "c72bb74e-5010-476f-a289-f63ff4e68572"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "for v in d.values():\n",
    "  print(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "learning\n",
      "intelligence\n",
      "programming\n",
      "language\n",
      "learning\n"
     ]
    }
   ],
   "source": [
    "for v in d2.values():\n",
    "  print(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language',\n",
       " 'deep': 'learning'}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 70
    },
    "colab_type": "code",
    "id": "j5Oyr1AFpC4f",
    "outputId": "98ea8ef2-915c-4dd4-d0c9-d5987b97b12d",
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Key: machine Value: learning\n",
      "Key: artificial Value: intelligence\n",
      "Key: java Value: programming\n",
      "Key: ruby Value: language\n",
      "Key: deep Value: learning\n"
     ]
    }
   ],
   "source": [
    "for k,v in d2.items():\n",
    "  print(\"Key:\", k, \"Value:\", v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "ffQvbfgepJVv",
    "outputId": "12edae3a-2b66-4279-e6fc-10c4f9d005b1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "course\n"
     ]
    }
   ],
   "source": [
    "for k,v in d.items():\n",
    "  if v == 2:\n",
    "    print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "fmxKFTs4pqwP",
    "outputId": "ed84dd19-da07-4772-bacf-be7d9f95e991"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'python': 1, 'course': 2}"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "iy6FAQxHpt6Q",
    "outputId": "a59e0324-fb84-4c14-e723-2e535c09105c"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'python': 1, 'course': 2, 'a': [3, 4, 5]}"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d[\"a\"] = [3,4,5]\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "AINo_32Upzyv",
    "outputId": "81ed10a8-59f8-4d29-afc5-f81281ae6541"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'course': 2, 'a': [3, 4, 5]}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.pop(\"python\")\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'python'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-53-f8be978652e7>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0md\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"python\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0md\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'python'"
     ]
    }
   ],
   "source": [
    "d.pop(\"python\")\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'course': 2, 'a': [3, 4, 5]}"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "U8QBwgp0sSJi",
    "outputId": "4f9ed760-c159-42e8-8a03-79180334dd79"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "89k7tFi_sWJO",
    "outputId": "ac845006-5d16-42f4-f51d-e974b74e4be8"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"a\" in d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "XdyIf0L1sYRM",
    "outputId": "bc09b449-a697-4c67-8ed4-e28ad9b6b118"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"aa\" in d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "oJvHWYyouN9w",
    "outputId": "c495cd2c-67ce-466d-82e4-7d47ec3a6fbf"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language',\n",
       " 'deep': 'learning'}"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 36
    },
    "colab_type": "code",
    "id": "uAtvUx9Jsf0w",
    "outputId": "d29e5cc0-99f0-4bb7-e5e3-4a625922c45b"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'programming'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.get(\"java\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "GobxPk3fuWi2"
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'd2' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-9ce9dbfa9305>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0md2\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Global AI Hub\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'd2' is not defined"
     ]
    }
   ],
   "source": [
    "d2.get(\"Global AI Hub\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language',\n",
       " 'deep': 'learning'}"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "nyH6npGYuhRD",
    "outputId": "b5a8ef56-c1cb-449b-9903-c426bb8c9fc7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language'}"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del d2[\"deep\"]\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language'}"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'Deep Learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language'}"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2['machine'] = \"Deep Learning\"\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'Deep Learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language'}"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2['machine'] = \"Deep Learning\"\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'Deep Learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language'}"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2_copy = d2.copy()\n",
    "d2_copy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'Deep Learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language',\n",
       " 'deep': 'AI'}"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2_copy['deep'] = 'AI'\n",
    "d2_copy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'machine': 'Deep Learning',\n",
       " 'artificial': 'intelligence',\n",
       " 'java': 'programming',\n",
       " 'ruby': 'language'}"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "rED5dTIhvSO6"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "human has 2 legs \n",
      "human has 2 legs.\n",
      "cat has 4 legs \n",
      "cat has 4 legs.\n",
      "spider has 8 legs \n",
      "spider has 8 legs.\n"
     ]
    }
   ],
   "source": [
    "d4 = {\"human\":2,\n",
    "      \"cat\":4,\n",
    "      \"spider\":8\n",
    "     }\n",
    "\n",
    "for i in d4:\n",
    "  leg = d4[i]\n",
    "  print(\"%s has %d legs \" % (i,leg))\n",
    "  print(str(i) + \" has \" + str(leg) +\" legs.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "CGzBpPlgwUTX"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "human has 2 legs.\n",
      "cat has 4 legs.\n",
      "spider has 8 legs.\n"
     ]
    }
   ],
   "source": [
    "d4 = {\"human\":2, \"cat\":4, \"spider\":8}\n",
    "\n",
    "for i,leg in d4.items():\n",
    "  print(str(i) + \" has \" + str(leg) +\" legs.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "SZia6YVqwfNU"
   },
   "outputs": [],
   "source": [
    "districts = {\"İstanbul\":[\"Bostancı\", \"Beşiktaş\", \"Kadıköy\"], \n",
    "           \"Ankara\":[\"Çankaya\", \"Gölbaşı\", \"Kızılcahamam\"],\n",
    "           \"İzmir\":[\"Çeşme\",\"Bornova\",\"Foça\"]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "4HyiNDwcwfAD",
    "outputId": "a86d855c-34d6-4fc9-8e7e-41e9a86886d5"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Bostancı', 'Beşiktaş', 'Kadıköy']"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "districts[\"İstanbul\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "CMpXSAUuxmmB",
    "outputId": "38b5e335-106e-42b7-c858-ce434d89d35e"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(districts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "yOyreuu_xqgL",
    "outputId": "87123a0c-a302-4bd5-a654-8068fd82540d"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(districts[\"Ankara\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 36
    },
    "colab_type": "code",
    "id": "jTxblvirxu9I",
    "outputId": "d36d9562-0810-4db1-9518-22c5345cae09"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Ç'"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "districts[\"İzmir\"][0][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 36
    },
    "colab_type": "code",
    "id": "b2gxQlCvyMcq",
    "outputId": "6aaa7b71-8b1c-4ea7-e638-5e4ea791648d"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Foça'"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "districts[\"İzmir\"][2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "Take2YvbyQSd",
    "outputId": "4a7d1fd9-e522-45a1-bfe0-677d77004955"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0: 0, 2: 4, 4: 16, 6: 36, 8: 64}\n"
     ]
    }
   ],
   "source": [
    "#creating a dictionary from a list\n",
    "\n",
    "\n",
    "nums = list(range(9)) # [0,1,2,3,4,5,6,7,8]\n",
    "\n",
    "even_sqr = {x: x**2 for x in nums if x % 2 == 0}\n",
    "print(even_sqr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "Ak4uMk3pzHZI"
   },
   "source": [
    "# Sets\n",
    "\n",
    "\n",
    "* A set, unlike lists, is a collection of data in no particular order; items cannot be accessed by indexing.\n",
    "* Just like mathematical sets, it cannot contain more than one of the same items.\n",
    "\n",
    "* An item can only be added once in sets. So a set cannot have two identical elements.\n",
    "* We use the set() function to create an empty set.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "QgZuDyx3yvn9",
    "outputId": "5661fe2b-3797-4b21-f74f-a5d733a64ad0"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{5, 6, 8, 'abc', 'python'}"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = {\"python\", 5,6,8,5,6,\"abc\", \"python\",\"python\",\"python\",\"python\",\"python\",\"python\",\"python\",\"python\",\"python\"}\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "KmzyF9b--0Ci",
    "outputId": "0fd6f24f-f616-40e2-da1e-ea76843cbcd7"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "set"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "empty = set()\n",
    "type(empty)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "8qLJrT9VAUvf",
    "outputId": "49d3a738-03e5-45f9-a284-eab1cd844848"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "empty2 = {}\n",
    "type(empty2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "cH4PCXOhAZpS",
    "outputId": "4de26760-75fc-49bc-dae2-a1b72febd89d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'abc', 5, 6, 8, 'python'}\n"
     ]
    }
   ],
   "source": [
    "s2 = set([\"python\", 5,6,8,5,6,\"abc\", \"python\"])\n",
    "print(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "TLu1Ec_bA__q"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'l', 'n', 'i', 'a', 'p', 'e'}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'a', 'e', 'i', 'l', 'n', 'p'}"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ne = set(\"pineapple\")\n",
    "print(ne)\n",
    "ne"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 186
    },
    "colab_type": "code",
    "id": "JEA3fgi7BXBR",
    "outputId": "ffaeb6f0-240c-4dea-a179-4b98c7051dca"
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unhashable type: 'dict'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-118-055bcfaf741a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m#Bu hata neden alındı.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;34m\"a\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"b\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'a'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m6\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'dict'"
     ]
    }
   ],
   "source": [
    "#Bu hata neden alındı.\n",
    "y = {\"a\",\"b\",{'a':[1,2,3]},5,6}\n",
    "print(y) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "WNZzrXshBy-0",
    "outputId": "7683a43d-ecba-44c9-bb94-c53a70bba02d"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{5, 6, 8, 'abc', 'python'}"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "k1IVnwKEB0Wn",
    "outputId": "c7eefb52-3522-4954-f90a-b7cdc30e4ee2"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "6 in s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "GUtmrwfhB2mj",
    "outputId": "d52e785c-6aa7-4397-ed56-a0599cdbe4f5"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "9 in s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "lPvxuypLB4Pg",
    "outputId": "f13d4e43-966b-4b31-8bdc-12093592e187"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "wCijI6-vCEj6",
    "outputId": "b59118c9-6059-4002-d1aa-283b6761f5f4"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{5, 6, 8, 'abc', 'ai', 'python'}"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.add(\"ai\")\n",
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 52
    },
    "colab_type": "code",
    "id": "tPq001PuCLO3",
    "outputId": "82b1466c-46b1-45f9-adc7-6b87b13c6763"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'abc', 5, 6, 8, 'python', 'ai'}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.add(\"ai\")\n",
    "print(s2)\n",
    "len(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "EGZnvf9WCRYk",
    "outputId": "2d503674-8139-4afc-bbbb-da3515931d25"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'abc', 5, 6, 8, 'python'}\n"
     ]
    }
   ],
   "source": [
    "s2.remove(\"ai\")\n",
    "print(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "wtZoskbUDQMN",
    "outputId": "effe7b2c-3db1-4a91-9e5e-99f0789e16cd"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}\n",
      "{0.0, 1.0, 2.0, 1.7320508075688772, 1.4142135623730951, 2.23606797749979, 2.449489742783178, 2.6457513110645907, 2.8284271247461903, 3.0}\n"
     ]
    }
   ],
   "source": [
    "#karekök bulma\n",
    "from math import sqrt\n",
    "\n",
    "#import math \n",
    "\n",
    "print({x for x in list(range(10))})\n",
    "\n",
    "print({sqrt(x) for x in list(range(10))})\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "sp_E8xAhG21y"
   },
   "source": [
    "# Tuples\n",
    "\n",
    "\n",
    "\n",
    "* It is an ordered data structure, it has an index value like lists, it can contain all data types.\n",
    "* Unlike lists, they have a structure that cannot be changed. If we have more than one unchangeable values, we can collect them in a bunch.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 52
    },
    "colab_type": "code",
    "id": "8Rui2302H8jD",
    "outputId": "c925805c-b8c6-48bd-ce59-62df117086be"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 4, 5)\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "tupl = (1,2,3,4,5)\n",
    "print(tupl)\n",
    "print(type(tupl))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "wZffTxPsIqqI",
    "outputId": "e043064f-a416-46bd-adcc-9f739ff992f9"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuple2 = ()  \n",
    "type(tuple2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "IrvB1HzGLYBZ",
    "outputId": "dab4ddd5-3799-493f-c314-8f71b67320b8"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "print(tupl[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "y_9FkBJORo5y",
    "outputId": "ec7d4abf-777d-4363-c014-9b5ed5c69101"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tupl[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "ZPMFZi-qRs4a",
    "outputId": "7b3703ec-141d-4ba4-9a4c-d48e3c9ce5d6"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, 4)"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tupl[:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "TeT5RXH1R6Gv",
    "outputId": "94499c40-f15e-4f5d-8c59-f68470a8ca10"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dm3 = (\"asli\", 5, 8, \"september\")\n",
    "dm3.index(\"september\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "wRks9wXwSRhJ",
    "outputId": "03b8bf14-973e-4413-c16d-60b29f14d26e"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dm3.count(5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 239
    },
    "colab_type": "code",
    "id": "Bo_JC5jkSWMf",
    "outputId": "c8777e9c-074f-42d5-9e72-bf7c154eb653"
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-139-4f4bd157cad3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mdm4\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m\"apple\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"pear\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"strawberry\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mdm4\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"cherry\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdm4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "dm4 = (\"apple\",\"pear\",\"strawberry\")\n",
    "\n",
    "dm4[0] = \"cherry\"\n",
    "\n",
    "print(dm4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-140-2bcdca579179>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mdm4\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m\"apple\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"pear\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"strawberry\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mdm4\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"cherry\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdm4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "dm4 = (\"apple\",\"pear\",\"strawberry\")\n",
    "\n",
    "dm4[3] = \"cherry\"\n",
    "\n",
    "print(dm4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('apple', 'pear', 'strawberry')"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dm4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "twLyvUivSoBr"
   },
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'tuple' object has no attribute 'remove'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-144-fd596d7b946d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdm4\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"pear\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'remove'"
     ]
    }
   ],
   "source": [
    "dm4.remove(\"pear\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "vSdY0CMtTLrH",
    "outputId": "46eabc10-590c-478e-9d08-10b78b3f1a5d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(0, 1): 0, (1, 2): 1, (2, 3): 2, (3, 4): 3, (4, 5): 4, (5, 6): 5, (6, 7): 6, (7, 8): 7, (8, 9): 8, (9, 10): 9}\n"
     ]
    }
   ],
   "source": [
    "# creating a dictionary in which tuples are keys.\n",
    "\n",
    "a = {(x, x+1): x for x in range(10)}\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "hX8AvulwTm-D",
    "outputId": "d25b0273-6de6-427c-8979-4a21b1c0309c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "s5 = (5,6)\n",
    "\n",
    "print(type(s5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "Cc0NzYWbT21n",
    "outputId": "994340a4-9c84-4ec7-ccc5-deeab889f5ee"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[s5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "id": "3XIfNKugUB1h",
    "outputId": "88af65b6-2839-49f5-9326-ad97e1807fda"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[(3,4)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [],
   "source": [
    "vegetables = ['squash', 'pea', 'carrot', 'potato']\n",
    "vegetables.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['carrot', 'pea', 'potato', 'squash']"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vegetables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['carrot', 'pea', 'potato', 'squash']"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vegetables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['apple', 'apricot', 'banana', 'pineapple', 'watermelon']"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fruit = ['watermelon','pineapple', 'apple', 'banana', 'apricot']\n",
    "sorted(fruit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['watermelon', 'pineapple', 'apple', 'banana', 'apricot']"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fruit"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "Day_4.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
